package com.rock.code.common.spring;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

/**
 * The type Spring cooikes.
 *
 * @author kongqiang
 * @date 2017.03.30
 */
public class SpringCooikes {

    /**
     * Add cookie.
     *
     * @param response the response
     * @param name     the name
     * @param value    the value
     * @author kongqiang
     * @date 2017.03.30
     */
    public static void addCookie(HttpServletResponse response, String name, String value) {
        Cookie cookie = new Cookie(name, value);
        cookie.setPath("/");
        response.addCookie(cookie);
    }

    /**
     * Add cookie.
     *
     * @param response the response
     * @param name     the name
     * @param value    the value
     * @param maxAge   the max age
     * @author kongqiang
     * @date 2017.03.30
     */
    public static void addCookie(HttpServletResponse response, String name, String value, int maxAge) {
        Cookie cookie = new Cookie(name, value);
        cookie.setPath("/");
        cookie.setMaxAge(maxAge);
        response.addCookie(cookie);

    }

    /**
     * Del cookie.
     *
     * @param response the response
     * @param name     the name
     * @author kongqiang
     * @date 2017.03.30
     */
    public static void delCookie(HttpServletResponse response, String name) {
        Cookie cookie = new Cookie(name, null);
        cookie.setPath("/");
        cookie.setMaxAge(0);
        response.addCookie(cookie);

    }
}
